https://leetcode.cn/problems/next-greater-node-in-linked-list/

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    vector<int> nextLargerNodes(ListNode* head) {

        vector<int> res;
        ListNode* cur = head;

        while (cur->next != NULL)
        {
            ListNode* next = cur->next;

            while (next != NULL && next->val <= cur->val)
                next = next->next;

            cur = cur->next;
            if (next != NULL)
                res.push_back(next->val);
            else
                res.push_back(0);

            next = cur->next;
        }
        res.push_back(0);

        return res;
    }
};